package component.controls
{
	import component.controls.ui.Component;
	import component.global.ComponentSetting;
	import component.global.manager.EventMgr;
	import component.global.utils.DisplayUtils;
	import component.global.utils.GraphicsUtils;
	import component.global.utils.ObjectUtil;
	
	import flash.events.MouseEvent;

	public class Button extends Component
	{
		public function Button($label:String = ComponentSetting.BUTTON_DEFAULT_LABEL,$width:int = ComponentSetting.BUTTON_DEFAULT_WIDTH,  $height:int = ComponentSetting.BUTTON_DEFAULT_HEIGHT)
		{
			_labelStr = $label;
			_width = $width;
			_height = $height;
			super();
		}
		
		protected var _label:Label
		protected var _labelStr:String;
		
		override protected function init():void
		{
			super.init();
			buttonMode = true;
			_background = GraphicsUtils.createRectangle(_width,_height);
			_background.filters = _filters[0];
			_label = new Label();
			_label.width = _background.width - 4;
			_label.height = _background.height;
			_label.x = 2;
			_label.text = _labelStr;
			
			EventMgr.Instance.addEvent(this,[MouseEvent.ROLL_OVER,MouseEvent.ROLL_OUT,MouseEvent.MOUSE_DOWN,MouseEvent.MOUSE_UP],[__onMouseEventHandler,__onMouseEventHandler,__onMouseEventHandler, __onMouseEventHandler]);
			DisplayUtils.addDisplayObject(this,_background,_label);
		}
		
		public function set label(value:String):void{
			_labelStr = value;
			_label.text = _labelStr;
		}
		
		public function get label():String
		{
			return _labelStr;
		}
		
		override public function set enabled(value:Boolean):void{
			super.enabled = value;
			if(_enabled){
				buttonMode = true;
			} else {
				buttonMode = false;
			}
		}
		
		override public function dispose():void
		{
			super.dispose();
			EventMgr.Instance.removeEvent(this);
			ObjectUtil.dispose(_label);_label=null;
		}
	}
}